<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="奖励人姓名">
              <el-input v-model="form.realname" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励人电话">
              <el-input v-model="form.username" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励人级别">
              <el-select v-model="form.roleId" placeholder="请选择">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="推荐人姓名">
              <el-input v-model="form.serversRealname" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="推荐人手机号">
              <el-input v-model="form.serversUsername" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励时间" width="236">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <!-- 导出按钮权限 -->
              <!-- v-if="permissionJson.indexOf('AdminServersRewardTransProvider.export') !=-1" -->
              <el-button class="el-icon-download" plain type="primary" @click="excelEvent">导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="realname" label="奖励人姓名" />
        <el-table-column prop="username" label="奖励人电话">
          <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="roleName" label="奖励人级别" />
        <!-- 1.2.1再加上 -->
        <el-table-column label="账号类型">
          <template slot-scope="scope">{{ scope.row.accountType|accountTypeFilter }}</template>
        </el-table-column>
        <el-table-column prop="amount" label="奖励金额" />
        <el-table-column label="比例">
          <template slot-scope="scope">{{ scope.row.rewardRate }}%</template>
        </el-table-column>
        <el-table-column prop="serversRealname" label="推荐人姓名" />
        <el-table-column prop="serversUsername" label="推荐人手机号">
          <template slot-scope="scope">
            <div>{{scope.row.serversUsername | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serversRoleName" label="推荐人级别" />
        <el-table-column prop="msg" label="信息" />
        <el-table-column prop="serversSigntimeStr" label="服务商加盟时间" />
        <el-table-column prop="createdAtStr" label="时间" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { merchantsFOIndexList, merchantsFOExport } from "@/api/financialOther";
import { exportfile } from "@/api/exporfile";
export default {
  name: "MerchantsFOIndex",
  filters: {
    accountTypeFilter(e) {
      switch (e) {
        case 1:
          return "普通";
          break;
        case 2:
          return "员工";
          break;
        case 3:
          return "特批";
          break;
        case 4:
          return "试用";
          break;
        case 5:
          return "369会员";
          break;
        case 6:
          return "颜咖";
          break;
        default:
          return "暂无";
          break;
      }
    }
  },
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: true,
      dates: [],
      form: {
        realname: "",
        username: "",
        roleId: null,
        serversRealname: "",
        serversUsername: "",
        serversRoleId: null,
        beginTime: "",
        endTime: "",
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      },
      roleOptions: [
        { id: null, name: "全部" },
        { id: 2, name: "美学设计师" },
        { id: 3, name: "高级美学设计师" },
        { id: 7, name: "总监" },
        { id: 8, name: "总监理" }
      ]
    };
  },
  mounted() {
    this.getList(this.listForm);
    // this.roleOptions = window.helper.roleFn('listReturn')
  },
  methods: {
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      merchantsFOIndexList(datas)
        .then(res => {
          // console.log(res)
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.beginTime = this.dates[0];
          this.form.endTime = this.dates[1];
        }
      } else {
        this.form.beginTime = "";
        this.form.endTime = "";
      }
      this.getList(this.form);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 导出
    excelEvent() {
      const datas = { ...this.form };
      delete datas.pageNum;
      delete datas.pageSize;
      merchantsFOExport(datas).then(res => {
        exportfile(res);
      });
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
